home *** CD-ROM | disk | FTP | other *** search
- .H:
- .H:
- .H: Charles G. Nemer CIS 166
- .H: WINDOW FUNCTIONS
- .H:
- .H:
- .N:19
- .F: Page.$$$
-
-
- /*****************************************************************************/
- /* Function window() is to create the window all that is needed */
- /* is to set up the upper left corner, the bottom right corner, */
- /* the border color (background-foreground), you should allready */
- /* have used set_color(background|foreground) for the window */
- /* itself. If a window can not be created window() will pass */
- /* back 0, if the window was created the window number will be */
- /* passed back. */
- /* If the window is to small it will not be allowed to fave a */
- /* border, the window with or without a border must be at least */
- /* one character space in size. All window are chained together */
- /* by pointers and you can move from one window to another. */
- /* window(0,0,24,79,1,0x70); */
- /*****************************************************************************/
-
- int window(char xb,char yb,char xe,char ye,char bdr,unsigned char bdcolor)
- {
- /*
- 0; { No border } For a border type pass one of
- 1; { Single border } the 13 different border numbers
- 2; { Double border }
- 3; { Mixed border }
- 4; { Mixed2 border }
- 5; { Solid border }
- 6; { Light hatch border }
- 7; { Medium hatch border }
- 8; { Dense hatch border }
- 9; { Mixed3 border }
- 10; { Mixed4 border }
- 11; { Mixed5 border }
- 12; { Mixed6 border }
- 13; { Mixed7 border }
- */
-
- int out;
- unsigned int size; /*size of window*/
- int far *address; /*address of window on screen*/
- char far *tempdata,char_address;
- int t,x,y,c,border;
- unsigned char border_char[13][8]={
- {'┌','┐','└','┘','─','─','│','│'}, /* single */
- {'╔','╗','╚','╝','═','═','║','║'}, /* double */
- {'╒','╕','╘','╛','═','═','│','│'}, /* mixed */
- {'╓','╖','╙','╜','─','─','║','║'}, /* mixed2 */
- {'█','█','█','█','█','█','▌','▐'}, /* solid */
- {'░','░','░','░','░','░','░','░'}, /* lhatch */
- {'▒','▒','▒','▒','▒','▒','▒','▒'}, /* mhatch */
- {'▓','▓','▓','▓','▓','▓','▓','▓'}, /* dhatch */
- {0xdf,0xdf,0xdc,0xdc,0xdf,0xdc,0xdd,0xde}, /* mixed3 */
- {0xda,0xbf,0xc0,0xd9,0xdf,0xdc,0xdd,0xde}, /* mixed4 */
- {0xda,0xbf,0xc0,0xd9,0xdb,0xdb,0xdb,0xdb}, /* mixed5 */
- {0xc9,0xbb,0xc8,0xbc,0xdf,0xdc,0xdd,0xde}, /* mixed6 */
- {0xc9,0xbb,0xc8,0xbc,0xdb,0xdb,0xdd,0xde} /* mixed7 */
- };
- curoff();
- /* if(ye>=num_col-1){ye=num_col-1;} /* check to see if the */
- if (xb>xe) {t=xb;xb=xe;xe=t;} /* window begining is */
- if (yb>ye) {t=yb;yb=ye;ye=t;} /* not after end */
- rowb=xb;
- colb=yb;
- rowe=xe;
- cole=ye;
- border=bdr;
- if(rowb+2>rowe){border=0;}
- if(colb+2>cole){border=0;}
-
- row=rowb;col=colb;
- size=(rowe-rowb+1)*(cole-colb+1)*2; /* check memory for room */
- if(farcoreleft() < 1000+size+sizeof(struct window_data))
- {curon();return(FALSE);} /* pass 0 if no room */
- else /* make window*/
- {/*1*/
- save_window(border,bdcolor,size); /* save old screen and window data */
- clrscr(); /* clear the new window using the color from set_color*/
- if(border>=1) /* if window has a border*/
- {/*end of else 1*/
- --border;
- for(row=rowb;row<=rowe;++row) /* draw border */
- {/*1*/
- if(rowb<row&&rowe>row) /* draw mid section of window*/
- {/*1*/
- for (y=0, col=colb;y<=1;y++,col=cole) /* to end of line*/
- {/*2*/
- if(col==colb) /* if first collum */
- {/*3*/
- c=(int)border_char[border][6]; /* c=left side */
- }/*end of if3*/
- else /* display right side */
- {/*2*/
- c=(int)border_char[border][7]; /* c=right side */
- }/*end of else2*/
- address = screenbase + ((row * num_col) + col);
- c=((bdcolor<<8)|c); /* add color to c and write to screen*/
- if(fast==TRUE) {foutput(address,c,1);} /* if no snow*/
- else output(address,c,1); /* if snow*/
- }/*end of for2*/
- continue; /* do next row*/
- }/*end of if2*/
-
- if(row==rowb) /* draw top line*/
- {/*4*/
- for (col=colb;col<=cole;++col) /* to end of line*/
- {/*3*/
- if(col==colb) /* if left corner*/
- { /*5*/
- c=(int)border_char[border][0]; /* c=left corner*/
- }/*end of if5*/
- else /* mid section*/
- {/*3*/
- c=(int)border_char[border][4]; /* c=mid section*/
- }/*end of else3*/
- if(col==cole) /* if right corner*/
- {/*6*/
- c=(int)border_char[border][1]; /* c=right corner*/
- }/*end of if6*/
- address = screenbase + ((row * num_col) + col); /* address where to put character*/
- c=((bdcolor<<8)|c); /* add color to c and write to screen*/
- if(fast==TRUE) {foutput(address,c,1);} /* if no snow use this*/
- else output(address,c,1); /* moniter has snow */
- }/*end of for3*/
- continue; /* draw next row*/
- }/*end of if4*/
-
- if(row==rowe) /* draw bottom line*/
- {/*7*/
- for (col=colb;col<=cole;++col) /* to end of line*/
- {/*4*/
- if(col==colb) /* if left corner*/
- {/*8*/
- c=(int)border_char[border][2]; /* c= bottom left corner*/
- }/*end of if8*/
- else /* if mid section*/
- {/*4*/
- c=(int)border_char[border][5]; /* c=mid section*/
- }/*end of else4*/
- if(col==cole) /* if right side*/
- {/*9*/
- c=(int)border_char[border][3]; /* c=bottom right corner*/
- }/*end of if9*/
- address = screenbase + ((row * num_col) + col); /* address where to put c*/
- c=((bdcolor<<8)|c); /* add color to c and write to screen*/
- if(fast==TRUE) {foutput(address,c,1);}/* no snow*/
- else output(address,c,1); /* snow*/
- }/*end of for4*/
- }/*end of if7*/
- }/*end of for1*/
- ++border; /* restore border*/
- }/*end of if1*/
-
- if(border>=1) /* if window has a*/
- { /*10*/ /* border shrink*/
- ++rowb; /* window to fit*/
- ++colb;
- --rowe;
- --cole;
- }/*end of if10*/ /* put cursor in */
- row=rowb;col=colb; /* right hand top */
- set_cur(rowb,colb); /* corner*/
- present->wcurr = row;
- present->wcurc = col;
- }/*end of else1*/
- curon();
- return(present->wnumber);
- }/*end of window()*/
-
-
-
-
- /*****************************************************************************/
- /* delete_window() will delete any window that you are not presently in. The */
- /* only time you can delete a window that you are is when you are at the end */
- /* of the chain and pass 0 to delete_window(0); . This will delete the end */
- /* window (link) and put you in the new end window (link). */
- /* delete_window is not smart yet so, if a window is on top of the window you*/
- /* delete the old data will be placed over the top window, so you must keep */
- /* track of the windows your self. */
- /* if window is not found 0 will be pass back and if window was deleted a -1 */
- /* will be returned. */
- /* You MUST use option 0 to delete the last window. */
- /* delete_window(5); */
- /*****************************************************************************/
-
- int delete_window(unsigned short wnum)
- {
- int far *windstore; /* pionters to save area*/
- int far *temp;
- unsigned int size;
- int x,y;
- unsigned short srowb,scolb,srowe,scole,
- snum_col,store_size;
- struct window_data far *windata; /* pionters to the window struct*/
- curoff();
- if(number_of_windows>0) /* if 0 no windows*/
- {/*1*/
- present->wcurr=row; /* save curser of present window*/
- present->wcurc=col;
- if(wnum>0) /* if not 0 find window to*/
- {/*2*/ /* delete*/
- windata=present; /* if not same as present*/
- if(windata->wnumber!=wnum) /* find*/
- {/*3*/
- if(windata->wnumber>wnum) /* go back*/
- {/*4*/
- while(windata->last!=NULL && windata->wnumber!=wnum) /* and find window or end of chain*/
- {windata=windata->last;}
- if(windata->wnumber!=wnum)return(FALSE); /* was window found or NULL if NULL return 0*/
- }/*end of if4*/
- else /* check to end*/
- {/*1*/ /*go fowards*/
- while(windata->next!=NULL && windata->wnumber!=wnum)
- {windata=windata->next;}
- if(windata->wnumber!=wnum)return(FALSE); /* if not found return -1*/
- }/*end of else1*/
- }/*end of if3*/
- else {curon();return(FALSE);} /* if same window, can not delete same window*/
- }/*end of if2*/ /* that you are on with this option*/
- else if(wnum==0)windata=last; /* used option 0 delete last window*/
- if(wnum>=0) /* delete window if a positive number*/
- {/*5*/
- if(last==windata)last=windata->last; /*set last window if new*/
- windstore=windata->addressave; /*get address of saved screen*/
- srowb=windata->wrowb;scolb=windata->wcolb; /*restore window data*/
- srowe=windata->wrowe;scole=windata->wcole;
- snum_col=windata->wnum_col;
- store_size=((scole-scolb)+1);
- for(row=srowb;row<=srowe;row++) /* restore screen */
- { /*1*/
- temp=screenbase+((row * snum_col) + scolb); /* address of screen pos*/
- if(fast==TRUE) {fscreen(temp,windstore,store_size);}/* no snow*/
- else screen_in(temp,windstore,store_size); /* snow*/
- windstore+=store_size; /* next line*/
- }/*end of for1*/
-
- }/*end of if5*/
- /* if last window was deleted*/
- if(wnum==0 && last!=NULL) /* restore if option 0*/
- {/*6*/ /* and window to restore*/
- present=last ; /* present window is last window*/
- wcolor=present->wcolor; /* get setup of*/
- rowb=present->wrowb;colb=present->wcolb; /* new present */
- rowe=present->wrowe;cole=present->wcole; /* window*/
- page=present->wpage;num_col=present->wnum_col;
- screenbase=present->screenbase;
- row=present->wcurr; col=present->wcurc;
- set_cur(row,col);
- if(present->bd>=1) /* if border shrink*/
- {/*7*/ /* window*/
- ++rowb;
- ++colb;
- --rowe;
- --cole;
- }/*end of if7*/
- }/*end of if6*/
-
-
-
- if(windata->next!=NULL && windata->last!=NULL) /* relink chain*/
- {/*8*/
- windata->last->next=windata->next;
- windata->next->last=windata->last;
- }/*end of if8*/
- else
- {/*3*/
- if(windata->last==NULL && windata->next!=NULL) /* or NULL end*/
- {windata->next->last=NULL;}
- if(windata->next==NULL && windata->last!=NULL)
- {windata->last->next=NULL;}
- }/*end of else3*/
-
- farfree(windata); /* free momory*/
- number_of_windows--; /* dec number of windows*/
- if(number_of_windows==0) /* if last windo restore*/
- {/*9*/ /* screen data*/
- num_col=fnum_col;
- page=fpage;
- row=frow;col=fcol;
- rowb=frowb;colb=fcolb;
- rowe=frowe;cole=fcole;
- screenbase=fscreenbase;
- wcolor=fcolor;
- set_cur(row,col);
- }/*end of if9*/
-
- }/*end of if1*/
- curon();
- return(TRUE);
- }/*end of main*/
-
-
-
- /*****************************************************************************/
- /* To change to another window all you have to do is pass the window number */
- /* assigned to it when make. If you can move to the window a -1 will be */
- /* passed back else a 0 if not. */
- /* change_window(5); */
- /*****************************************************************************/
-
- change_window(unsigned short wnum)
- {
- unsigned short num;
- struct window_data far *windo,far *windata;
- windata=present;
- reg.h.ah = 3; /* get cursor position */
- reg.h.bh = page; /* page */
- int86(0x10,®,®);
- windata->wcurr = reg.h.dh; /* update this window struct*/
- windata->wcurc = reg.h.dl; /* befor moving*/
- if(windata->wnumber!=wnum) /* find new window*/
- {
- if(windata->wnumber>wnum) /* is window you are at after*/
- { /* window you need*/
- while(windata->last!=NULL&&windata->wnumber!=wnum)
- {windata=windata->last;} /* move back*/
- if(windata->wnumber!=wnum)return(FALSE); /* if not found return false*/
- }
- else
- { /* window is befor window you need*/
- while(windata->next!=NULL&&windata->wnumber!=wnum)
- {windata=windata->next;} /* get next window*/
- if(windata->wnumber!=wnum)return(FALSE); /* not found*/
- }
- present=windata; /* found window*/
- row=windata->wcurr; col=windata->wcurc; /* get cursor data*/
- set_cur(row,col); /* set cursor*/
- wcolor=windata->wcolor;
- rowb=windata->wrowb;colb=windata->wcolb; /* restore window data*/
- rowe=windata->wrowe;cole=windata->wcole;
- page=windata->wpage;num_col=windata->wnum_col;
- screenbase=windata->screenbase;
- if(windata->bd>=1) /* if a border make window fit*/
- {
- ++rowb;
- ++colb;
- --rowe;
- --cole;
- }
- }
- return(TRUE);
- }
-
-
-